using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;

public partial class Includes_jQuery_SamplePage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    [WebMethod]
    public static TestReturn TestMethod(TestArgs args)
    {
        if (args != null && !string.IsNullOrEmpty(args.Letters))
        {
            List<TestReturnChild> ch = new List<TestReturnChild>();
            foreach (char c in args.Letters.ToCharArray()) ch.Add(new TestReturnChild() {
                Letter = c.ToString(),
                Guid = Guid.NewGuid().ToString()
            });

            return new TestReturn()
            {
                Guid = Guid.NewGuid().ToString(),
                Random = new Random().Next(),
                Children = ch.ToArray()
            };
        }
        else
        {
            return new TestReturn()
            {
                Guid = Guid.NewGuid().ToString(),
                Random = new Random().Next(),
                Children = new TestReturnChild[] {
                    new TestReturnChild() {
                        Guid = Guid.NewGuid().ToString(),
                        Letter = "J"
                    }
                }
            };
        }
    }

    [Serializable]
    public class TestReturn
    {
        public string Guid { get; set; }
        public int Random { get; set; }
        public TestReturnChild[] Children { get; set; }
    }

    [Serializable]
    public class TestReturnChild
    {
        public string Guid { get; set; }
        public string Letter { get; set; }
    }

    [Serializable]
    public class TestArgs
    {
        public string Letters { get; set; }
    }
}
